home *** CD-ROM | disk | FTP | other *** search
/ ASP Advantage 1993 / The Association of Shareware Professionals Advantage CD-ROM 1993.iso / files / commions / ca29_1 / ca29_3.exe / BBMAINT2.CMD < prev    next >
OS/2 REXX Batch file  |  1992-03-24  |  24KB  |  907 lines

  1. ;****    TRACE ON        ; Debugging
  2. ;
  3. ; ----- COM-AND BBS file maintenance script (Files file)
  4. ;    Commenced: 11/90 R.McG
  5. ; -----------------------------------------------------------------------
  6. ;    Purpose:
  7. ;       The script, named BBMAINT2.CMD, produces the main window for
  8. ;    Filedir functions of BBMAINT, and implements its functions.  It
  9. ;    is not directly callable itself.
  10. ; -----------------------------------------------------------------------
  11. ;    Usage:
  12. ;       N99 -> Text attribute value (Setup by BBMAINT.CMD)
  13. ;       N98 -> BBMAINT Mainline cursor position
  14. ;       N97 -> BBMAINT Mainline cursor position
  15. ;       N96 -> our mainline cursor position
  16. ;       N95 -> our mainline cursor position
  17. ; -----------------------------------------------------------------------
  18. ;
  19. ;    This script is intended ONLY to be used for FCALL
  20. ;
  21.     IF NOT FCALLED
  22.        WOPEN 10,10,13,70 (cont) NOFIEsc
  23.        ATSAY 10,12 (cont) " BBS Files "
  24.        ATSAY 11,12 (cont) " The script: "*"_SCRIPT"
  25.        ATSAY 12,12 (cont) " is not used by itself... it is called through BBMAINT"
  26.        ATSAY 13,26 (cont) " Press any key to continue "
  27.        ;
  28.        ;    Wait a keypress
  29.        ;
  30.        KEYGET S0        ; Wait for any key
  31.        WCLOSE        ; Close open window
  32.        EXIT         ; Terminate right here
  33.        ENDIF
  34.     GOSUB FileFile        ; Invoke function
  35.     FRETURN         ; Return to caller
  36. ; -----------------------------------------------------------------------
  37. ; ----- NoFile:  Inform that there's no BBS-FIle file to modify
  38. ;
  39. NoFile:
  40.     WOPEN 10,10,13,70 (cont) NOFIEsc
  41.     ATSAY 10,12 (cont) " BBS FileDir "
  42.     ATSAY 11,12 (cont) " The file: "*S23&"\BBS-File"
  43.     ATSAY 12,12 (cont) " does not exist.  Please create subdirectories first."
  44.     ATSAY 13,26 (cont) " Press any key to continue "
  45.     ;
  46.     ;    Wait a keypress
  47.     ;
  48.     KEYGET S0        ; Wait for any key
  49.     WCLOSE
  50. NOFIEsc:
  51.     RETURN
  52. ; -----------------------------------------------------------------------
  53. ; ----- Subroutine: FileFile -> Update FILE directory
  54. ;
  55. FileFile:
  56.     GOSUB NewFile        ; Create if not there
  57.     IF NOT ISFILE S23&"\BBS-FIle"
  58.        GOSUB NoFile     ; Inform there's no file
  59.        RETURN        ; .. so we can't continue
  60.        ENDIF
  61. ;
  62. ;    Open a window
  63. ;
  64.     WOPEN 0,0 23,79 (defa) File_Esc
  65.     ATSAY 0,2 (defa)   " BBS Files "
  66.     ATSAY 23,25 (defa) " Press ESC to cancel BBMAINT "
  67. ;
  68. ;    Paint the window
  69. ;
  70. FIFI100:
  71.     CLEAR            ; Clear window
  72.     LOCATE 2,2
  73.  
  74.     MESS " 1) Add a file to the up/download list"
  75.     MESS " 2) Delete a file from the list"
  76.     MESS " 3) Modify a file's listing"
  77.     MESS " 4) Print the file list"
  78.     MESS " 5) View the file list"
  79.     MESS "──────────────────────────────────── "
  80.     MESS "Note: Alt-Q to edit a file"
  81.     MESS "      Alt-F for a directory search"
  82.     MESS "      Alt-F10 to shell to DOS"
  83.     MESS " "
  84.     MESS "──────────────────────────────────── "
  85.     MESS " "
  86.     MESS "Select item (carriage return = previous): "
  87.     CURSOR N96,N95        ; Read current cursor
  88. ;
  89. ;    Wait for entry, and interpret
  90. ;
  91. FIFI200:
  92.     LOCATE N96 N95        ; Reposition cursor
  93.     KEYGET S0        ; Wait for it
  94.     SWITCH S0        ; Act according to keyget
  95.       CASE "1"
  96.            GOSUB AddFile
  97.            ENDCASE
  98.       CASE "2"
  99.            GOSUB DelFile
  100.            ENDCASE
  101.       CASE "3"
  102.            GOSUB ModFile
  103.            ENDCASE
  104.       CASE "4"
  105.            GOSUB PrnFile
  106.            ENDCASE
  107.       CASE "5"
  108.            GOSUB ViewFile
  109.            GOTO FIFI100    ; Repaint after this
  110.            ENDCASE
  111.       CASE "0d"             ; c/r alone is exit
  112.            WCLOSE        ; Close window...
  113.            RETURN        ; and return to caller
  114.            ENDCASE
  115.       CASE "_NULL"          ; ESC -> Null
  116.            WCLOSE        ; Close window...
  117.            RETURN        ; Leave Main routine
  118.            ENDCASE
  119.       CASE "2100"           ; Alt-F
  120.            MANUAL "0x2100"  ; Perform Dir cmd
  121.            ENDCASE
  122.       CASE "1000"           ; Alt-Q
  123.            MANUAL "0x1000"  ; Edit a file
  124.            ENDCASE
  125.       CASE "7100"           ; Alt-F10
  126.            SHELL
  127.            DWINDOW 1,2,22,78; Reset dwindow after shell
  128.            LEGEND "_LEGEND" ; Redo the legend
  129.            ENDCASE
  130.       DEFAULT        ; None of the above
  131.            SOUND 100,100    ; Bronx cheer
  132.            ENDCASE
  133.       ENDSWITCH
  134.     GOTO FIFI200        ; Repaint screen and ask again
  135. ;
  136. ;    End of Files procedure
  137. ;
  138. File_Esc:
  139.     S0 = ""                 ; Fake null entry
  140.     RETURN            ; Leave files routine
  141. ; -----------------------------------------------------------------------
  142. ; ----- AddFile:  Add a file to the File directory
  143. ;
  144. AddFile:
  145.     SET FLAG(0) OFF     ; Flag for ESCAPE
  146.     WOPEN 10,10,16,75 (cont) ADFIEsc
  147.     ATSAY 10,12 (cont) " BBS Files Add "
  148.     ATSAY 11,12 (cont) "Enter the file to be added: "
  149.     ATSAY 16,26 (cont) " Press ESC to cancel "
  150.     ;
  151.     ;    Wait a keypress
  152.     ;
  153.     LOCATE 11,42
  154.     GET S0 12        ; get fname
  155.     IF FLAG(0) GOTO ADFIEnd ; Exit if ESC hit
  156.     LJ S0            ; Left justify - don't upper case
  157.     IF NULL S0 GOTO ADFIEnd ; get out on empty entry
  158.     GOSUB LkpFile        ; Lookup name in files file
  159.     IF FOUND        ; If its there we can't add it
  160.        WCLOSE        ; Close open window
  161.        GOTO ModFI_Add    ; Skip if file found
  162.        ENDIF
  163.     S10 = S0        ; Save File name
  164.     GOTO ADFI100        ; And branch around parallel code
  165. ;
  166. ;    Entry from ModFile... Nothing to modify
  167. ;
  168. AddFI_Mod:
  169.     WOPEN 10,10,16,75 (cont) ADFIEsc
  170.     ATSAY 10,12 (cont) " BBS Files Add "
  171.     ATSAY 11,12 (cont) "Enter the file to be added: "
  172.     ATSAY 11,42 (cont) S0
  173.     ATSAY 16,26 (cont) " Press ESC to cancel "
  174.     S10 = S0        ; Copy it for remainder
  175. ;
  176. ;    Look for the file - Add date and size to listing
  177. ;
  178. ADFI100:
  179.     FDATE S1 S23&"\"&S0     ; Ask for the file date (bbs-file subdir)
  180.     IF FAILED GOTO ADFI110    ; Skip if d.n.e
  181.     S10(12:19) = S1     ; Place date of file
  182.     FSIZE S1 S23&"\"&S0     ; Ask for the file size (bbs-file subdir)
  183.     IF FAILED GOTO ADFI110    ; Skip if d.n.e
  184.     S10(21:27) = S1     ; Place size of file (7 digits)
  185.     ATSAY 12,12 (cont) "File date and size:"
  186.     ATSAY 12,42 (cont) S10(12:27)
  187.     GOTO ADFI200        ; SKip around error handler
  188. ;
  189. ;    File does not exist...
  190. ;
  191. ADFI110:
  192.     ATSAY 12,12 (cont) "File d.n.e. Add anyway (y/n): "
  193.     LOCATE 12,42
  194.     GET S0 1        ; get resp
  195.     IF FLAG(0) GOTO ADFIEnd ; Exit if ESC hit
  196.     IF NULL S0 or NOT FIND "YN" S0(0)
  197.        SOUND 100,100    ; Indicate displeasure
  198.        GOTO ADFI110     ; Try again
  199.        ENDIF
  200.     IF FIND "N" S0(0)
  201.        WCLOSE        ; Close window
  202.        GOTO AddFile     ; And try again
  203.        ENDIF
  204.     S10(12:27) = "******** ********"
  205. ;
  206. ;    Ask for a comment field
  207. ;
  208. ADFI200:
  209.     ATSAY 13,12 (cont) "Comment text: "
  210.     LOCATE 13,26
  211.     GET S0 40        ; get resp
  212.     LJ S0            ; Left justify
  213.     IF FLAG(0) GOTO ADFIEnd ; Exit if ESC hit
  214.     IF NULL S0
  215.        SOUND 100,100    ; Indicate displeasure
  216.        GOTO ADFI200     ; Try again
  217.        ENDIF
  218.     S10(28:79) = S0     ; Save comment text
  219. ;
  220. ;    Ask for privileged flag
  221. ;
  222. ADFI250:
  223.     ATSAY 14,12 (cont) "Priveleged access (y/n):  "
  224.     LOCATE 14,42
  225.     GET S0 1        ; get resp
  226.     IF FLAG(0) GOTO ADFIEnd ; Exit if ESC hit
  227.     IF NULL S0 or NOT FIND "YN" S0(0)
  228.        SOUND 100,100    ; Indicate displeasure
  229.        GOTO ADFI250     ; Try again
  230.        ENDIF
  231.     IF FIND "Y" S0(0) S10(20:20) = "P" ; Save priveleged access
  232. ;
  233. ;    Ask for one more look
  234. ;
  235. ADFI300:
  236.     ATSAY 15,12 (cont) "OK to add this record?:   "
  237.     LOCATE 15,42
  238.     GET S0 1        ; get resp
  239.     IF FLAG(0) GOTO ADFIEnd ; Exit if ESC hit
  240.     IF NULL S0 or NOT FIND "YN" S0(0)
  241.        SOUND 100,100    ; Indicate displeasure
  242.        GOTO ADFI300     ; Try again
  243.        ENDIF
  244.     IF FIND "N" S0(0)
  245.        WCLOSE        ; Close window
  246.        GOTO AddFile     ; And try again
  247.        ENDIF
  248. ;
  249. ;    Write the record
  250. ;
  251.     GOSUB AddFRec        ; Write to Files file
  252. ;
  253. ;    End of add procedure
  254. ;
  255. ADFIEnd:
  256.     WCLOSE
  257. ADFIEsc:
  258.     SET FLAG(0) ON
  259.     RETURN
  260. ; -----------------------------------------------------------------------
  261. ; ----- AddFRec:  Add a record to the file file...
  262. ;    .. S10 passes the record to be written
  263. ;
  264. AddFRec:
  265.     FOPENO S23&"\BBS-File" TEXT APPEND
  266.     IF NOT SUCCESS        ; Open failed
  267.        S0 = "Error opening: "*S23&"\BBS-File"
  268.        GOSUB Error        ; Report
  269.        RETURN        ; And we're done
  270.        ENDIF
  271.     PRESERVE S10        ; Preserve ^'s and !'s
  272.     WRITE S10        ; Write the record
  273.     WRITE "!^Z"             ; And finish it
  274.     FCLOSEO
  275.     RETURN
  276. ; -----------------------------------------------------------------------
  277. ; ----- LkpFile:  Lookup a file in the BBS-File file
  278. ;    .. S0 passes the fname to be tested
  279. ;    .. S10 returns the record read
  280. ;
  281. LkpFIle:
  282.     FOPENI S23&"\BBS-File" TEXT
  283.     IF NOT SUCCESS        ; Open failed
  284.        S0 = "Error opening: "*S23&"\BBS-File"
  285.        GOSUB Error        ; Report
  286.        SET FOUND OFF    ; Not found
  287.        RETURN        ; And we're done
  288.        ENDIF
  289. ;
  290. ;    Read loop
  291. ;
  292. LOFI100:
  293.     READ S10 80 N0        ; Read a record
  294.     IF EOF GOTO LOFI200    ; Skip on EOF
  295.     IF STRCMP S10(0:0) "<" GOTO LOFI110
  296.     IF STRCMP S10(0:11) S0(0:11) GOTO LOFI300
  297. ;
  298. ;    Record longer than 80 chars
  299. ;
  300. LOFI110:
  301.     IF N0 LT 80 GOTO LOFI100; If exactly 80 rtnd, c/r wasn't read
  302.     READ S10 80 N0        ; Read remainder of rec
  303.     GOTO LOFI110        ; Read until less than 80
  304. ;
  305. ;    We have end-of-file - not found
  306. ;
  307. LOFI200:
  308.     SET FOUND OFF        ; Indicate not found
  309.     GOTO LOFIEnd
  310. ;
  311. ;    We have a hit - return found
  312. ;
  313. LOFI300:
  314.     SET FOUND ON        ; Indicate found
  315. ;
  316. ;    And exit
  317. ;
  318. LOFIEnd:
  319.     FCLOSEI
  320.     RETURN
  321. ; -----------------------------------------------------------------------
  322. ; ----- DelFile:  Delete a file  from Files file
  323. ;
  324. DelFile:
  325.     SET FLAG(0) OFF     ; Flag for ESCAPE
  326.     WOPEN 10,10,15,70 (cont) DEFIEsc
  327.     ATSAY 10,12 (cont) " BBS Files Delete "
  328.     ATSAY 11,12 (cont) "Enter the file to be deleted: "
  329.     ATSAY 15,26 (cont) " Press ESC to cancel "
  330.     ;
  331.     ;    Wait a keypress
  332.     ;
  333.     LOCATE 11,42
  334.     GET S0 12        ; get resp
  335.     IF FLAG(0) GOTO DEFIEnd ; Exit if ESC hit
  336.     LJ S0            ; Left justify - don't upper case
  337.     IF NULL S0 GOTO DEFIEnd ; get out on empty entry
  338. ;
  339. ;    Open the File file and a temp copy file
  340. ;
  341.     GOSUB DelFRec        ; Try to delete a record
  342.     IF FLAG(1) GOTO DEFIEnd ; Skip if record deleted
  343.     ATSAY 12,12 (cont) "File not in listing...     "
  344.     ATSAY 13,12 (cont) "Press any key to continue..."
  345.     KEYGET S0
  346. ;
  347. ;    End of add procedure
  348. ;
  349. DEFIEnd:
  350.     WCLOSE
  351. DEFIEsc:
  352.     SET FLAG(0) ON
  353.     RETURN
  354. ; -----------------------------------------------------------------------
  355. ; ----- DelFRec:  Delete a record from the Files file...
  356. ;    .. S0 passes the File name key
  357. ;    .. S1 destroyed in the process
  358. ;    .. FLAG(1) if rtn'd set, indicates record was FOUND
  359. ;
  360. DelFRec:
  361. ;
  362. ;    Open the Files file and a temp copy file
  363. ;
  364.     SET FLAG(1)  OFF    ; Initialize for found flag
  365.     FOPENI S23&"\BBS-File" TEXT
  366.     IF NOT SUCCESS        ; Open failed
  367.        S0 = "Error opening: "*S23&"\BBS-File"
  368.        GOSUB Error        ; Report
  369.        GOTO DEFREnd     ; And we're done
  370.        ENDIF
  371.  
  372.     FOPENO S23&"\TempFile" TEXT
  373.     IF NOT SUCCESS        ; Open failed
  374.        S0 = "Error opening: "*S23&"\TempFile"
  375.        GOSUB Error        ; Report
  376.        GOTO DEFREnd     ; And we're done
  377.        ENDIF
  378.     N10 = 0         ; Count recs written
  379. ;
  380. ;    Read records (40 chars at a time to allow PRESERVE)
  381. ;
  382. DEFR100:
  383.     READ S1 40 N0        ; Read 1st 40 chars
  384.     IF EOF GOTO DEFR300    ; Skip on EOF
  385.     IF STRCMP S1(0:11) S0(0:11) GOTO DEFR200
  386.     INC N10
  387. ;
  388. ;    Copy the record read to the output file
  389. ;
  390. DEFR110:
  391.     PRESERVE S1        ; Save !'s and ^'s
  392.     WRITE S1        ; Write text
  393.  
  394.     IF N0 LT 40        ; If we wrote end of record
  395.        WRITE "!"            ; Finish w/cr/lf
  396.        GOTO DEFR100     ; And continue copying
  397.        ENDIF
  398.     READ S1 40 N0        ; Read remainder of rec
  399.     IF NOT EOF GOTO DEFR110 ; Skip if not eof
  400.     WRITE "!"               ; Finish record
  401.     GOTO DEFR300        ; End of file
  402. ;
  403. ;    We have a hit
  404. ;
  405. DEFR200:
  406.     SET FLAG(1) ON        ; Flag we deleted item
  407.     IF N0 LT 40 GOTO DEFR100
  408.     READ S1 40 N0        ; Read remainder of rec
  409.     IF NOT EOF GOTO DEFR200 ; Skip if not found
  410. ;
  411. ;    We hit EOF - may or may not have found the target rec
  412. ;
  413. DEFR300:
  414.     IF NOT FLAG(1) GOTO DEFR400 ; skip if not found
  415.     WRITE "^Z"              ; Finish ASCII file
  416.     FCLOSEO         ; Close output
  417.     FCLOSEI         ; Close input
  418.     DELETE S23&"\BBS-File"  ; Delete original
  419.     RENAME S23&"\TempFile" S23&"\BBS-File"
  420.     IF ZERO N10 DELETE S23&"\BBS-File" ; Delete empty file
  421.     GOTO DEFREnd
  422. ;
  423. ;    We hit EOF - we did not find the record
  424. ;
  425. DEFR400:
  426.     FCLOSEO         ; Close output
  427.     FCLOSEI         ; Close input
  428.     DELETE S23&"\TempFile"  ; Delete copy file
  429. ;
  430. ;    End of procedure...
  431. ;
  432. DEFREnd:
  433.     RETURN
  434. ; -----------------------------------------------------------------------
  435. ; ----- ModFile:  Modify a file in the Files file
  436. ;
  437. ModFile:
  438.     SET FLAG(0) OFF     ; Flag for ESCAPE
  439.     WOPEN 10,10,17,75 (cont) MOFIEsc
  440.     ATSAY 10,12 (cont) " BBS Files Modify "
  441.     ATSAY 11,12 (cont) "Enter the fname to change: "
  442.     ATSAY 17,26 (cont) " Press ESC to cancel "
  443.     ;
  444.     ;    Wait a keypress
  445.     ;
  446.     LOCATE 11,42
  447.     GET S0 12        ; get resp
  448.     IF FLAG(0) GOTO MOFIEnd ; Exit if ESC hit
  449.     LJ S0            ; Left justify - don't upper case
  450.     IF NULL S0 GOTO MOFIEnd ; get out on empty entry
  451.     GOSUB LkpFile        ; Lookup File in Files file
  452.     IF NOT FOUND        ; If its there we can't add it
  453.        WCLOSE        ; Close open window
  454.        GOTO AddFI_Mod    ; Skip if NOT found
  455.        ENDIF
  456.     GOTO MOFI100        ; And branch around parallel code
  457. ;
  458. ;    Entry from AddFile... We have a rec in S10 - needs adding
  459. ;
  460. ModFI_Add:
  461.     WOPEN 10,10,17,75 (cont) MOFIEsc
  462.     ATSAY 10,12 (cont) " BBS Files Modify "
  463.     ATSAY 11,12 (cont) "Enter the File to change: "
  464.     ATSAY 11,42 (cont) S0
  465.     ATSAY 17,26 (cont) " Press ESC to cancel "
  466. ;
  467. ;    Display the original values (rtnd in S10 by LkpFile)
  468. ;
  469. MOFI100:
  470.     ATSAY 10,54 (cont) " Old vals "
  471.     ATSAY 11,55 (cont) S10(0:11)
  472.     ATSAY 12,55 (cont) S10(12:19)*" "*S10(21:27)
  473.     ATSAY 14,26 (cont) S10(28:79)
  474.     IF NOT NULL S10(20:20)
  475.        ATSAY 15,55 (cont) "y"
  476.     ELSE
  477.        ATSAY 15,55 (cont) "n"
  478.        ENDIF
  479. ;
  480. ;    Look for the file - Add date and size to listing
  481. ;
  482.     FDATE S1 S23&"\"&S0     ; Ask for the file date (bbs-file subdir)
  483.     IF FAILED GOTO MOFI110    ; Skip if d.n.e
  484.     S10(12:19) = S1     ; Place date of file
  485.     FSIZE S1 S23&"\"&S0     ; Ask for the file size (bbs-file subdir)
  486.     IF FAILED GOTO MOFI110    ; Skip if d.n.e
  487.     S10(21:27) = S1     ; Place size of file (7 digits)
  488.     ATSAY 12,12 (cont) "File date and size:"
  489.     ATSAY 12,33 (cont) S10(12:19)*" "*S10(21:27)
  490.     GOTO MOFI200        ; SKip around error handler
  491. ;
  492. ;    File does not exist...
  493. ;
  494. MOFI110:
  495.     ATSAY 12,12 (cont) "File d.n.e. Add anyway (y/n): "
  496.     LOCATE 12,42
  497.     GET S0 1        ; get resp
  498.     IF FLAG(0) GOTO MOFIEnd ; Exit if ESC hit
  499.     IF NULL S0 or NOT FIND "YN" S0(0)
  500.        SOUND 100,100    ; Indicate displeasure
  501.        GOTO MOFI110     ; Try again
  502.        ENDIF
  503.     IF FIND "N" S0(0)
  504.        WCLOSE        ; Close window
  505.        GOTO ModFile     ; And try again
  506.        ENDIF
  507.     S10(12:27) = "******** ********"
  508. ;
  509. ;    Ask for a comment field
  510. ;
  511. MOFI200:
  512.     ATSAY 13,12 (cont) "Comment text: "
  513.     LOCATE 13,26
  514.     GET S0 40        ; get resp
  515.     LJ S0            ; Left justify
  516.     IF FLAG(0) GOTO MOFIEnd ; Exit if ESC hit
  517.     IF NULL S0        ; If null entry...
  518.        ATSAY 13,26 (cont) S10(28:67)
  519.        GOTO MOFI250     ; Skip store
  520.        ENDIF
  521.     S10(28:79) = S0     ; Save comment text
  522. ;
  523. ;    Ask for privileged flag
  524. ;
  525. MOFI250:
  526.     ATSAY 15,12 (cont) "Priveleged access (y/n):  "
  527.     LOCATE 15,42
  528.     GET S0 1        ; get resp
  529.     IF FLAG(0) GOTO MOFIEnd ; Exit if ESC hit
  530.     IF NULL S0 ATSCR 13,55 1 S0 ; Read back previous value
  531.     IF NOT FIND "YN" S0(0)  ; If not y/n
  532.        SOUND 100,100    ; Indicate displeasure
  533.        GOTO MOFI250     ; Try again
  534.        ENDIF
  535.     S10(20:20) = " "        ; Default no priv
  536.     IF FIND "Y" S0(0)       ; If privilege 'y'
  537.        S10(20:20) = "P"     ; Set priveleged access
  538.        ENDIF
  539. ;
  540. ;    Ask for one more look
  541. ;
  542. MOFI300:
  543.     ATSAY 16,12 (cont) "OK to add this record?:   "
  544.     LOCATE 16,42
  545.     GET S0 1        ; get file
  546.     IF FLAG(0) GOTO MOFIEnd ; Exit if ESC hit
  547.     IF NULL S0 or NOT FIND "YN" S0(0)
  548.        SOUND 100,100    ; Indicate displeasure
  549.        GOTO MOFI300     ; Try again
  550.        ENDIF
  551.     IF FIND "N" S0(0)
  552.        WCLOSE        ; Close window
  553.        GOTO ModFile     ; And try again
  554.        ENDIF
  555. ;
  556. ;    Delete the previous value... and add the new
  557. ;    .. Could do a Delete/add but don't want file re-ordered
  558. ;
  559.     GOSUB ModFRec        ; Delete the previous key
  560.     IF NOT FLAG(1)        ; If not deleted
  561.        S0 = "Error modifying record for: "*S0
  562.        GOSUB Error        ; Report
  563.        GOTO MOFIEnd     ; And we're done
  564.        ENDIF
  565. ;
  566. ;    End of add procedure
  567. ;
  568. MOFIEnd:
  569.     WCLOSE
  570. MOFIEsc:
  571.     SET FLAG(0) ON
  572.     RETURN
  573. ; -----------------------------------------------------------------------
  574. ; ----- ModFRec:  Modify a record from the Files file...
  575. ;    .. S10 passes the new record (same file name key)
  576. ;    .. S1 destroyed in the process
  577. ;
  578. ModFRec:
  579. ;
  580. ;    Open the Files file and a temp copy file
  581. ;
  582.     SET FLAG(1)  OFF    ; Initialize for found flag
  583.     FOPENI S23&"\BBS-File" TEXT
  584.     IF NOT SUCCESS        ; Open failed
  585.        S0 = "Error opening: "*S23&"\BBS-File"
  586.        GOSUB Error        ; Report
  587.        GOTO MOFREnd     ; And we're done
  588.        ENDIF
  589.  
  590.     FOPENO S23&"\TempFile" TEXT
  591.     IF NOT SUCCESS        ; Open failed
  592.        S0 = "Error opening: "*S23&"\TempFile"
  593.        GOSUB Error        ; Report
  594.        GOTO MOFREnd     ; And we're done
  595.        ENDIF
  596.     N10 = 0         ; Count recs written
  597. ;
  598. ;    Read records (40 chars at a time to allow PRESERVE)
  599. ;
  600. MOFR100:
  601.     READ S1 40 N0        ; Read 1st 40 chars
  602.     IF EOF GOTO MOFR300    ; Skip on EOF
  603.     IF STRCMP S1(0:11) S10(0:11) GOTO MOFR200
  604.     INC N10
  605. ;
  606. ;    Copy the record read to the output file
  607. ;
  608. MOFR110:
  609.     PRESERVE S1        ; Save !'s and ^'s
  610.     WRITE S1        ; Write text
  611.  
  612.     IF N0 LT 40        ; If we wrote end of record
  613.        WRITE "!"            ; Finish w/cr/lf
  614.        GOTO MOFR100     ; And continue copying
  615.        ENDIF
  616.     READ S1 40 N0        ; Read remainder of rec
  617.     IF NOT EOF GOTO MOFR110 ; Skip if not eof
  618.     WRITE "!"               ; Finish record
  619.     GOTO MOFR300        ; End of file
  620. ;
  621. ;    We have a match on the key.
  622. ;
  623. MOFR200:
  624.     SET FLAG(1) ON        ; Flag we deleted item
  625.     S1 = S10(0:39)        ; Take 1st part of rec to write
  626.     PRESERVE S1        ; Save !s and ^s
  627.     WRITE S1        ; Write text
  628.  
  629.     LENGTH S10 N1        ; Get new rec length
  630.     IF N1 LT 40 GOTO MOFR210
  631.  
  632.     S1 = S10(40:79)     ; Take 2nd part of rec to write
  633.     PRESERVE S1        ; Save !s and ^s
  634.     WRITE S1        ; Write text
  635. ;
  636. ;    Finish the new record
  637. ;
  638. MOFR210:
  639.     WRITE "!"               ; Finish record
  640. ;
  641. ;    Finish reading the original record
  642. ;
  643. MOFR220:
  644.     IF N0 LT 40 GOTO MOFR100
  645.     READ S1 40 N0        ; Read remainder of rec
  646.     IF NOT EOF GOTO MOFR220 ; Skip if not found
  647. ;
  648. ;    We hit EOF - may or may not have found the target rec
  649. ;
  650. MOFR300:
  651.     IF NOT FLAG(1) GOTO MOFR200 ; skip if not found
  652.     WRITE "^Z"              ; Finish ASCII file
  653.     FCLOSEO         ; Close output
  654.     FCLOSEI         ; Close input
  655.     DELETE S23&"\BBS-File"  ; Delete original
  656.     RENAME S23&"\TempFile" S23&"\BBS-File"
  657.     IF ZERO N10 DELETE S23&"\BBS-File" ; Delete empty file
  658. ;
  659. ;    End of procedure...
  660. ;
  661. MOFREnd:
  662.     RETURN
  663. ; -----------------------------------------------------------------------
  664. ; ----- PrnFIle:  Print a file listing
  665. ;
  666. PrnFile:
  667.     FOPENI S23&"\BBS-File" TEXT
  668.     IF NOT SUCCESS        ; Open failed
  669.        S0 = "Error opening: "*S23&"\BBS-File"
  670.        GOSUB Error        ; Report
  671.        RETURN        ; And we're done
  672.        ENDIF
  673. ;
  674. ;    Initialize a counter
  675. ;
  676.     N10 = 0         ; # Lines printed
  677.     N11 = 1         ; Page number
  678. ;
  679. ;    Read loop
  680. ;
  681. PRFI100:
  682.     READ S10 80 N0        ; Read a record
  683.     IF EOF GOTO PRFI200    ; Skip on EOF
  684.     IF STRCMP S10(0:0) "*" GOTO PRFI120 ; skip comments
  685.     IF ZERO N0 GOTO PRFI100 ; skip blank lines
  686. ;
  687. ;    Print a heading...
  688. ;
  689.     IF N10 GT 0 and N10 LE 50 GOTO PRFI110
  690.     PRINT "COM-AND Scripted BBS File list as of "*"_DATE"*", "*"_TIME"*"      Page "*N11*"^M^J"
  691.     PRINT "From: "*"_IFILE"*"^M^J"
  692.     PRINT "---------------------------------------------------------------------^M^J"
  693.     PRINT "Name         Priv Date     Size    Description^M^J"
  694.     PRINT "------------ ---- -------- ------- ----------------------------------^M^J"
  695.     N10 = 0
  696.     INC N11
  697. ;
  698. ;    Build a record and print it
  699. ;
  700. PRFI110:
  701.     S0 = S10(0:11)        ; File name
  702.     IF NOT NULL S10(20:20) S0(14:16) = "yes"
  703.     S0(18:79)  = S10(12:19) ; Date
  704.     S0(27:79)  = S10(21:27) ; size
  705.     S0(35:79)  = S10(28:79) ; comment field
  706.     PRESERVE S0
  707.     PRINT S0
  708.     PRINT "^M^J"            ; FInish line
  709.     INC N10         ; COunt lines printed
  710. ;
  711. ;    Handle record longer than 80 chars
  712. ;
  713. PRFI120:
  714.     IF N0 LT 80 GOTO PRFI100; If exactly 80 rtnd, c/r wasn't read
  715.     READ S10 80 N0        ; Read remainder of rec
  716.     GOTO PRFI120        ; Read until less than 80
  717. ;
  718. ;    We have end-of-file
  719. ;
  720. PRFI200:
  721.     PRINT "^L"              ; Do a final top-of-form
  722. ;
  723. ;    And exit
  724. ;
  725. PRFIEnd:
  726.     FCLOSEI
  727.     RETURN
  728. ; -----------------------------------------------------------------------
  729. ; ----- ViewFile: View a list of files
  730. ;
  731. ViewFile:
  732.     FOPENI S23&"\BBS-File" TEXT
  733.     IF NOT SUCCESS        ; Open failed
  734.        S0 = "Error opening: "*S23&"\BBS-File"
  735.        GOSUB Error        ; Report
  736.        RETURN        ; And we're done
  737.        ENDIF
  738. ;
  739. ;    Initialize a counter
  740. ;
  741.     N10 = 0         ; # Lines printed
  742.     N11 = 0         ; Page number
  743.     SET FLAG(0) OFF     ; Initialize esc flag
  744.     S11 = "_ONESC"
  745.     ON ESCAPE GOSUB VIFIESC
  746. ;
  747. ;    Print a heading...
  748. ;
  749. VIFI100:
  750.     IF N10 GT 0 GOTO VIFI110
  751.     CLEAR            ; Clear the window
  752.     ATSAY 1,2 (defa) "Name         Priv Date     Size    Description"
  753.     ATSAY 2,2 (defa) "------------ ---- -------- ------- ----------------------------------"
  754.     N10 = 3         ; Set starting line no
  755.     INC N11         ; Set next page
  756. ;
  757. ;    Save the file position for the start of this page
  758. ;
  759.     FSAVEI
  760.     IF NOT SUCCESS
  761.        FSAVEI SHIFT     ; Save last 20 pos'ns
  762.        FSAVEI
  763.        ENDIF
  764. ;
  765. ;    Read loop
  766. ;
  767. VIFI110:
  768.     READ S10 80 N0        ; Read a record
  769.     IF EOF GOTO VIFI200    ; Skip on EOF
  770.     IF STRCMP S10(0:0) "*" GOTO VIFI120 ; skip comments
  771.     IF ZERO N0 GOTO VIFI110 ; skip blank lines
  772. ;
  773. ;    Build a record and print it
  774. ;
  775.     S0 = S10(0:11)        ; File name
  776.     IF NOT NULL S10(20:20) S0(14:16) = "yes"
  777.     S0(18:74)  = S10(12:19) ; Date
  778.     S0(27:74)  = S10(21:27) ; size
  779.     S0(35:74)  = S10(28:79) ; comment field
  780.     PRESERVE S0
  781.     ATSAY N10,2 (defa) S0
  782.     INC N10         ; COunt lines printed
  783. ;
  784. ;    Handle record longer than 80 chars
  785. ;
  786. VIFI120:
  787.     IF N0 LT 80 GOTO VIFI200; If exactly 80 rtnd, c/r wasn't read
  788.     READ S10 80 N0        ; Read remainder of rec
  789.     GOTO VIFI120        ; Read until less than 80
  790. ;
  791. ;    Look for end of screen/end of file
  792. ;
  793. VIFI200:
  794.     IF (NOT EOF) and N10 LT 21 GOTO VIFI100
  795.     IF EOF
  796.        ATSAY 22,2 (defa) "End of file; Home (top), PgDn (forward), PgUp (back)"
  797.     ELSE
  798.        ATSAY 22,2 (defa) "Page "*N11*"; Home (top), PgDn (forward), PgUp (back)"
  799.        ENDIF
  800. ;
  801. ;    Read a key and interpret
  802. ;
  803. VIFI210:
  804.     IF FLAG(0) RETURN    ; End of routine when flag set
  805.     KEYGET S1
  806.     IF FLAG(0) RETURN    ; End of routine when flag set
  807.     SWITCH S1
  808.       CASE "4900"           ; Pgup
  809.         GOTO PgUp
  810.         ENDCASE
  811.       CASE "5100"           ; PgDn
  812.         GOTO PgDn
  813.         ENDCASE
  814.       CASE "4700"           ; Home
  815.         GOTO Home
  816.         ENDCASE
  817.       CASE "0D"             ; C/r
  818.         IF EOF GOTO VIFIEnd
  819.         GOTO PgDn
  820.         ENDCASE
  821.       CASE "2100"           ; Alt-F
  822.         MANUAL "0x2100"     ; Perform Dir cmd
  823.         ENDCASE
  824.       CASE "1000"           ; Alt-Q
  825.         MANUAL "0x1000"     ; Edit a file
  826.         ENDCASE
  827.       CASE "7100"           ; Alt-F10
  828.         SHELL
  829.         DWINDOW 1,2,22,78    ; Reset dwindow after shell
  830.         LEGEND "_LEGEND"    ; Redo the legend
  831.         ENDCASE
  832.       DEFAULT
  833.         MESS S1
  834.         SOUND 100,100
  835.         ENDCASE
  836.       ENDSWITCH
  837.     GOTO VIFI210
  838. ;
  839. ;    Page up (go backwards)
  840. ;
  841. PgUp:
  842.     N10 = 0         ; Clear line ctr
  843.     FRESTOREI        ; Backup current pg
  844.     N11 = N11-1        ; Reset Page # for redisplay
  845.     FRESTOREI        ; Backup one more
  846.     IF NOT SUCCESS
  847.        SOUND 200,100    ; Indicate problem
  848.        GOTO Home
  849.        ENDIF
  850.     N11 = N11-1        ; Reset Page # for redisplay
  851.     GOTO VIFI100
  852. ;
  853. ;    Home (go to top)
  854. ;
  855. Home:
  856.     N10 = 0         ; Clear line ctr
  857.     N11 = 0         ; Set new pg number
  858.     FSAVEI CLEAR        ; Clear saved pages
  859.     REWIND            ; Rewind input
  860.     GOTO VIFI100
  861. ;
  862. ;    Page down (go forwards)
  863. ;
  864. PgDn:
  865.     IF EOF GOTO Home    ; Wrap to home at EOF
  866.     N10 = 0         ; Clear line ctr
  867.     GOTO VIFI100
  868. ;
  869. ;    And exit
  870. ;
  871. VIFIEnd:
  872.     FCLOSEI
  873.     RETURN
  874. ;
  875. ;    Escape entered
  876. ;
  877. VIFIESC:
  878.     SET FLAG(0) ON
  879.     ON ESCAPE GOSUB S11    ; Restore previous ON ESC
  880.     RETURN
  881. ; -----------------------------------------------------------------------
  882. ; ----- Subroutine: NewFile -> Create a new BBS-File file
  883. ;
  884. NewFile:
  885.     IF ISFILE S23&"\BBS-File" RETURN
  886.     FOPENO S23&"\BBS-File" TEXT
  887.     IF NOT SUCCESS RETURN    ; Open failed
  888.     WRITE "!^Z"             ; Make it empty
  889.     FCLOSEO         ; Done with it
  890.     RETURN
  891. ; -----------------------------------------------------------------------
  892. ; ----- Error:    Open a window, display a message, and wait for keypress
  893. ;    S0 passes the error message
  894. ;
  895. Error:
  896.     WOPEN 10,10,12,70 (cont) Err_Esc
  897.     ATSAY 10,12 (cont) " Error "
  898.     ATSAY 11,12 (cont) S0(0:55); Max msg width 55 chars
  899.     ATSAY 12,26 (cont) " Press any key to continue "
  900.     ;
  901.     ;    Wait a keypress
  902.     ;
  903.     KEYGET S0        ; Wait for any key
  904.     WCLOSE
  905. Err_Esc:
  906.     RETURN
  907.